import json

import requests

url = "https://qianfan.baidubce.com/v2/app/conversation"

payload = json.dumps({
    "app_id": "c82ac281-a0b3-45cf-9aad-6386d4457aff"
})
headers = {
    'Content-Type': 'application/json',
    'X-Appbuilder-Authorization': 'Bearer bce-v3/ALTAK-6ba68uzv9bbRr7ozO40Pt/342eb107eafe7fbfba9d6331d34ab51f64919f6a'
}

response = requests.request("POST", url, headers=headers, data=payload)

data = json.loads(response.text)
conversation_id = data['conversation_id']

url = "https://qianfan.baidubce.com/v2/app/conversation/runs"

payload = json.dumps({
    "app_id": "c82ac281-a0b3-45cf-9aad-6386d4457aff",
    "query": input('请输入问题：'),
    "stream": False,
    "conversation_id": "88563f76-ac47-424f-8f2e-343c9932a59a"
})
headers = {
    'Content-Type': 'application/json',
    'X-Appbuilder-Authorization': 'Bearer bce-v3/ALTAK-6ba68uzv9bbRr7ozO40Pt/342eb107eafe7fbfba9d6331d34ab51f64919f6a'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
data = json.loads(response.text)
print(data['answer'])